import { defHttp } from '@/utils/http/axios';
import { ErrorMessageMode } from '#/axios';
import { BaseResponse, PagerResponse, AbsPageQuery } from '@/api/base';

// 定义接口地址
enum Api {
  /** 批量删除 */
  BATCH_DELETE = '/toolkit/column/batchDelete',
  /** 删除 */
  DELETE_BY_ID = '/toolkit/column/delete/',
  /** 查询基本信息 */
  DETAIL = '/toolkit/column/',
  /** 列表查询 */
  LIST = '/toolkit/column/list',
  /** 分页查询 */
  PAGER = '/toolkit/column/pager',
  /** 新增 */
  SAVE = '/toolkit/column/save',
  /** 修改 */
  UPDATE = '/toolkit/column/update/',
}

// 定义参数类型

export interface ColumnDO {
  id?: number;
  createTime?: Date;
  updateTime?: Date;
  schemaName?: string;
  tableName?: string;
  tableId?: number;
  columnName?: string;
  columnType?: string;
  columnFullType?: string;
  columnDefault?: string;
  columnComment?: string;
  ordinalPosition?: number;
  charMaxLength?: number;
  numMaxLength?: number;
  numScale?: number;
  fieldType?: string;
  nullable?: boolean;
  isPk?: boolean;
  isUnsigned?: boolean;
  autoIncrement?: boolean;
  autoTimeOnCreate?: boolean;
  autoTimeOnUpdate?: boolean;
  status?: number;
  fieldName?: string;
  fieldLabel?: string;
  searchEnable?: boolean;
  searchWindth?: number;
  searchType?: string;
  searchComponent?: string;
  searchEnterEnable?: boolean;
  listEnable?: string;
  listWidth?: any;
  listAlign?: string;
  listComponent?: string;
  listExportEnable?: boolean;
  listImportEnable?: boolean;
  listBatchDeleteEnable?: boolean;
  listShowIdx?: boolean;
  insertEnable?: boolean;
  updateEnable?: boolean;
  updateEdit?: boolean;
  editRequired?: boolean;
  editRules?: string;
}

export interface ColumnQuery extends AbsPageQuery{
  id?: number;
  createTime?: Date;
  updateTime?: Date;
  schemaName?: string;
  tableName?: string;
  tableId?: number;
  columnName?: string;
  columnType?: string;
  columnFullType?: string;
  columnDefault?: string;
  columnComment?: string;
  ordinalPosition?: number;
  charMaxLength?: number;
  numMaxLength?: number;
  numScale?: number;
  fieldType?: string;
  nullable?: boolean;
  isPk?: boolean;
  isUnsigned?: boolean;
  autoIncrement?: boolean;
  autoTimeOnCreate?: boolean;
  autoTimeOnUpdate?: boolean;
  status?: number;
  fieldName?: string;
  fieldLabel?: string;
  searchEnable?: boolean;
  searchWindth?: number;
  searchType?: string;
  searchComponent?: string;
  searchEnterEnable?: boolean;
  listEnable?: string;
  listWidth?: any;
  listAlign?: string;
  listComponent?: string;
  listExportEnable?: boolean;
  listImportEnable?: boolean;
  listBatchDeleteEnable?: boolean;
  listShowIdx?: boolean;
  insertEnable?: boolean;
  updateEnable?: boolean;
  updateEdit?: boolean;
  editRequired?: boolean;
  editRules?: string;
}

export interface ColumnRequest {
  id?: number;
  createTime?: Date;
  updateTime?: Date;
  schemaName?: string;
  tableName?: string;
  tableId?: number;
  columnName?: string;
  columnType?: string;
  columnFullType?: string;
  columnDefault?: string;
  columnComment?: string;
  ordinalPosition?: number;
  charMaxLength?: number;
  numMaxLength?: number;
  numScale?: number;
  fieldType?: string;
  nullable?: boolean;
  isPk?: boolean;
  isUnsigned?: boolean;
  autoIncrement?: boolean;
  autoTimeOnCreate?: boolean;
  autoTimeOnUpdate?: boolean;
  status?: number;
  fieldName?: string;
  fieldLabel?: string;
  searchEnable?: boolean;
  searchWindth?: number;
  searchType?: string;
  searchComponent?: string;
  searchEnterEnable?: boolean;
  listEnable?: string;
  listWidth?: any;
  listAlign?: string;
  listComponent?: string;
  listExportEnable?: boolean;
  listImportEnable?: boolean;
  listBatchDeleteEnable?: boolean;
  listShowIdx?: boolean;
  insertEnable?: boolean;
  updateEnable?: boolean;
  updateEdit?: boolean;
  editRequired?: boolean;
  editRules?: string;
}

// 定义接口方法
// 批量删除
export function batchDelete(params: number[], mode: ErrorMessageMode = 'message') {
  return defHttp.post<BaseResponse<number>>(
    {
      url: Api.BATCH_DELETE,
      params,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// 删除
export function deleteById(id: number, mode: ErrorMessageMode = 'message') {
  return defHttp.delete<BaseResponse<boolean>>(
    {
      url: Api.DELETE_BY_ID + '/' + id,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// 查询基本信息
export function detail(id: number, mode: ErrorMessageMode = 'message') {
  return defHttp.get<BaseResponse<ColumnDO>>(
    {
      url: Api.DETAIL + '/' + id,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// 列表查询
export function list(params: ColumnQuery, mode: ErrorMessageMode = 'message') {
  return defHttp.post<BaseResponse<Array<ColumnDO>>>(
    {
      url: Api.LIST,
      params,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// 分页查询
export function pager(params: ColumnQuery, mode: ErrorMessageMode = 'message') {
  return defHttp.post<BaseResponse<PagerResponse<ColumnDO>>>(
    {
      url: Api.PAGER,
      params,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// 新增
export function save(params: ColumnRequest, mode: ErrorMessageMode = 'message') {
  return defHttp.post<BaseResponse<number>>(
    {
      url: Api.SAVE,
      params,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// 修改
export function update(id: number, params: ColumnRequest, mode: ErrorMessageMode = 'message') {
  return defHttp.put<BaseResponse<boolean>>(
    {
      url: Api.UPDATE + '/' + id,
      params,
    },
    {
      errorMessageMode: mode,
    },
  );
}
